/** 
 * All Rights Reserved , Copyright (C) 2023 , 青岛鼎信通讯股份有限公司
 * 
 *CbbPmReplayController
 * 项目复盘会
 * 
 * 修改纪录
 * 2023-07-21 版本：1.0 caozhiyuan 创建。
 * @version 版本：1.0
 * @author 作者：caozhiyuan
 * 创建日期：2023-07-21
 */

package com.topscomm.mis.cbb.pm.controller;

import java.util.Map;

import com.topscomm.mis.cbb.pm.api.IReplayService;
import com.topscomm.pub.util.BaseUtil;
import com.topscomm.pub.vo.Page;
import com.topscomm.tap.constant.TapHttpErrorCode;
import com.topscomm.tap.constant.TapHttpStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.topscomm.mis.cbb.pm.controller.auto.CbbPmReplayControllerAuto;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;

/**
 * @author: caozhiyuan
 * @date: 2023-07-21
 * @description:项目复盘会Controller
 * @modify:
 */
@RestController
@RequestMapping("base/cbbPmReplay")
public class CbbPmReplayController extends CbbPmReplayControllerAuto {

	@Autowired
	private IReplayService replayService;

	/**
	 * @author: caozhiyuan
	 * @date: 2023-07-21
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	protected String spellListSql(Map<String, Object> paraMap) {
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle(" 1=1 ");
		if (paraMap.containsKey("qry_name")) {
			String value = paraMap.get("qry_name").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and name like '%{0}%' ", value);
		}
		if (paraMap.containsKey("qry_code")) {
			String value = paraMap.get("qry_code").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and code = '{0}' ", value);
		}
		// 参照列表多选查询
		if (paraMap.containsKey("qry_fieldkey") && paraMap.containsKey("qry_keys")) {
			String fieldKey = paraMap.get("qry_fieldkey").toString();
			String keys = paraMap.get("qry_keys").toString();
			if (!StringUtil.isEmpty(fieldKey) && !StringUtil.isEmpty(keys)) {
				sql.appendSingle(" and {0} in ({1})", fieldKey, keys);
			}
		}
		return sql.toString();
	}

	/**
	 * @author: caozhiyuan
	 * @date: 2023-07-24 09:16:00
	 * @description: 列表页
	 * @return:
	 * @modify:
	 */
	@GetMapping(value = "/list")
	public ResponseResult<Object> list(
			@RequestParam(required = false) Map<String, Object> paraMap) {
		try {
			BaseUtil.decodeSecureMap(paraMap);
			String sqlWhere = this.spellListSql(paraMap);
			Page page = replayService.list(paraMap, sqlWhere);
			return ResponseResult.ok(page);
		} catch (Exception ex) {
			return ResponseResult
					.error(TapHttpStatus.HTTP_INTERNAL_ERROR, TapHttpErrorCode.ERROR, ex.getMessage());
		}
	}

	/**
	 * @author: caozhiyuan
	 * @date: 2023-07-24 09:16:17
	 * @param: paraMap
	 * @description: 详情页
	 * @return: com.topscomm.pub.vo.ResponseResult<java.lang.Object>
	 * @modify:
	 */
	@GetMapping(value = "/load")
	public ResponseResult<Object> load(@RequestParam(required = false) Map<String, Object> paraMap) {
		BaseUtil.decodeSecureMap(paraMap);
		Map<String, Object> dataMap = replayService.load(paraMap);
		return ResponseResult.ok(dataMap);
	}

	/**
	 * @author: caozhiyuan
	 * @date: 2023-07-24 09:16:17
	 * @param: paraMap
	 * @description: 根据projectuucode获取详情页
	 * @return: com.topscomm.pub.vo.ResponseResult<java.lang.Object>
	 * @modify:
	 */
	@GetMapping(value = "/loadByProjectUUcode")
	public ResponseResult<Object> loadByProjectUUcode(@RequestParam(required = false) Map<String, Object> paraMap) {
		BaseUtil.decodeSecureMap(paraMap);
		Map<String, Object> dataMap = replayService.loadByProjectUUcode(paraMap);
		return ResponseResult.ok(dataMap);
	}

	/**
	 * @author: caozhiyuan
	 * @date: 2023-07-24 09:16:34
	 * @param: paraMap
	 * @description: 插入数据
	 * @return: com.topscomm.pub.vo.ResponseResult<java.lang.Object>
	 * @modify:
	 */
	@PostMapping(value = "/insert")
	public ResponseResult<Object> insert(
			@RequestBody(required = false) Map<String, Object> paraMap) {
		try {
			Map<String, Object> resMap = replayService.insert(paraMap);
			return ResponseResult.ok(resMap);
		} catch (Exception e) {
			return ResponseResult
					.error(TapHttpStatus.HTTP_INTERNAL_ERROR, TapHttpErrorCode.ERROR, e.getMessage());
		}

	}

	/**
	 * @author: caozhiyuan
	 * @date: 2023-07-24 09:16:44
	 * @param: paraMap
	 * @description: 更新
	 * @return: com.topscomm.pub.vo.ResponseResult<java.lang.Object>
	 * @modify:
	 */
	@PutMapping(value = "/update")
	public ResponseResult<Object> update(
			@RequestBody(required = false) Map<String, Object> paraMap) {
		try {
			replayService.update(paraMap);
			return ResponseResult.ok("修改成功");
		}catch (Exception e){
			return ResponseResult
					.error(TapHttpStatus.HTTP_INTERNAL_ERROR, TapHttpErrorCode.ERROR, e.getMessage());
		}
	}

	/**
	 * @author: caozhiyuan
	 * @date: 2023-07-24 09:16:55
	 * @param: paraMap
	 * @description: 删除
	 * @return: com.topscomm.pub.vo.ResponseResult<java.lang.Object>
	 * @modify:
	 */
	@DeleteMapping(value = "/delete")
	public ResponseResult<Object> delete(@RequestBody(required = false) Map<String, Object> paraMap) {
		BaseUtil.decodeSecureMap(paraMap);
		replayService.delete(paraMap);
		return ResponseResult.ok("删除成功");
	}
}

